package com.javaxiaobear.module.system.controller;

import com.javaxiaobear.base.common.utils.StringUtils;
import com.javaxiaobear.base.framework.security.RegisterBody;
import com.javaxiaobear.base.framework.security.service.SysRegisterService;
import com.javaxiaobear.base.framework.web.controller.BaseController;
import com.javaxiaobear.base.framework.web.domain.AjaxResult;
import com.javaxiaobear.module.system.service.ISysConfigService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册验证
 *
 * @author javaxiaobear
 */
@RestController
public class SysRegisterController extends BaseController {
  @Resource SysRegisterService registerService;

  @Resource ISysConfigService configService;

  @PostMapping("/register")
  public AjaxResult register(@RequestBody RegisterBody user) {
    if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
      return error("当前系统没有开启注册功能！");
    }
    String msg = registerService.register(user);
    return StringUtils.isEmpty(msg) ? success() : error(msg);
  }
}
